package com.egg.auth.enums.account;


import com.egg.common.swagger.annotation.SwaggerDisplayAnnotation;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * 用户账号枚举类
 *
 * @author east
 */
@Getter
@SwaggerDisplayAnnotation
@AllArgsConstructor
public enum AccountTypeEnum {


    PASSWORD("password", "账号密码"),
    APPLET("applet", "微信小程序登录"),
    WECHAT("wechat", "微信登录"),
    PHONE("phone", "手机验证码"),

    ;


    private String code;
    private String message;

    public static Optional<AccountTypeEnum> find(String code) {
        if (Objects.isNull(code)) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(o -> Objects.equals(code, o.getCode())).findAny();
    }

    @Override
    public String toString() {
        return message + ":" + code;
    }
}
